package com.quarkus.security.jdbc.service;

import com.quarkus.security.jdbc.entity.User;
import org.jboss.logging.Logger;

import javax.enterprise.context.ApplicationScoped;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@ApplicationScoped
public class UserService {

	private static final Logger LOGGER = Logger.getLogger(UserService.class);
	private Map<Integer, User> projectMap = new HashMap<>();

	public UserService() {
		projectMap.put(1, new User(1, "项目A", "关于项目A的情况描述"));
		projectMap.put(2, new User(2, "项目B", "关于项目B的情况描述"));
		projectMap.put(3, new User(3, "项目C", "关于项目C的情况描述"));
       
	}	
	

	public List<User> getAllProject() {
		return new ArrayList<>(projectMap.values());
	}
	
	public User getProjectById(Integer id) {
        return projectMap.get(id);
    }

	public List<User> add(User project) {
		projectMap.put(projectMap.size()+1,project);
		return new ArrayList<>(projectMap.values());
	}

	public List<User> update(User project) {
		
		if (projectMap.containsKey(project.id))	{
			projectMap.replace(project.id, project);			
		}		
		return new ArrayList<>(projectMap.values());
	}

	public List<User> delete(User project) {
		if (projectMap.containsKey(project.id))	{
			projectMap.remove(project.id);			
		}		
		return new ArrayList<>(projectMap.values());
	}
	
	public String getProjectInform() {
		String projectContent = "";
		for (User value : projectMap.values()) {
			String projectInform = "{项目名称：" + value.name + "，" + "项目描述："
					+ value.description + "}";
			projectContent = projectContent + projectInform;
		}
		return projectContent;
	}
	

}
